#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project ：machine_learning_warehouse 
@File ：鸢尾花机器学习分类.py
@IDE  ：PyCharm 
@Author ：李涵彬
@Date ：2024/11/29 16:32 
"""

from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
from sklearn.metrics import classification_report

# 加载数据集
iris = load_iris()
X, y = iris.data, iris.target

# 划分训练集和测试集
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)

# 创建K近邻分类器
knc = KNeighborsClassifier(n_neighbors=3)

# 训练模型
knc.fit(X_train, y_train)

# 预测测试集
y_pred = knc.predict(X_test)

# 评估模型
print(classification_report(y_test, y_pred, target_names=iris.target_names))
